package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.BaseBuildInfo;
import com.softer.wxzj.entity.BuildAddAudit;
import com.softer.wxzj.entity.OrgBuildAudit;
import com.softer.wxzj.entity.OrgRegionAudit;
import com.softer.wxzj.service.OrgBuildAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 自然幢区域绑定
 *
 * @author Gong Zhiyang
 * @date 2020/5/28
 */
@RestController
@RequestMapping("/orgBuild")
public class OrgBuildAuditController {
    @Autowired
    private OrgBuildAuditService orgBuildAuditService;

    /**
     * 查询绑定的自然幢列表
     *
     * @param page          分页实体
     * @param baseBuildInfo 查询实体
     * @return 自然幢列表
     */
    @PostMapping("/getOrgBuildAuditList")
    @LogRecord(description = "查询绑定的自然幢列表", operationUnit = LogOperationUnit.ORG_BUILD, operationType = LogOperationType.SELECT)
    public PageInfo<BaseBuildInfo> getOrgBuildAuditList(Page page, BaseBuildInfo baseBuildInfo) {
        return orgBuildAuditService.getOrgBuildAuditList(page, baseBuildInfo);
    }

    /**
     * 查询绑定的自然幢列表
     * 用于下拉列表
     *
     * @param baseBuildInfo 查询实体
     * @return 自然幢列表
     */
    @PostMapping("/getAllOrgBuildAuditList")
    @LogRecord(description = "查询绑定的所有自然幢列表", operationUnit = LogOperationUnit.ORG_BUILD, operationType = LogOperationType.SELECT)
    public List<BaseBuildInfo> getAllOrgBuildAuditList(BaseBuildInfo baseBuildInfo) {
        return orgBuildAuditService.getAllOrgBuildAuditList(baseBuildInfo);
    }

    /**
     * 查询小区下可以绑定的自然幢列表
     * （自己物业下已经保存的，审核中的，审核通过的不查询）
     *
     * @param regionId 小区ID
     * @param operNo   外网登录账号
     * @return 自然幢列表
     */
    @PostMapping("/getAddBuildList")
    @LogRecord(description = "查询小区下可以绑定的自然幢列表", operationUnit = LogOperationUnit.ORG_BUILD, operationType = LogOperationType.SELECT)
    public List<BaseBuildInfo> getAddBuildList(String regionId, String operNo) {
        return orgBuildAuditService.getAddBuildList(regionId, operNo);
    }

    /**
     * 删除绑定的自然幢（只有未提交审核的可以删除）
     *
     * @param orgBuildAuditId 绑定的自然幢ID
     * @return 删除结果
     */
    @PostMapping("/deleteAudit")
    @LogRecord(description = "删除绑定的自然幢", operationUnit = LogOperationUnit.ORG_BUILD, operationType = LogOperationType.DELETE)
    public CommonResult deleteAudit(String orgBuildAuditId) {
        return orgBuildAuditService.deleteAudit(orgBuildAuditId);
    }

    /**
     * 新增绑定的自然幢
     *
     * @param buildAddAudit 绑定的自然幢ID集合
     * @return 结果
     */
    @PostMapping("/addAudit")
    @LogRecord(description = "新增绑定的自然幢", operationUnit = LogOperationUnit.ORG_BUILD, operationType = LogOperationType.INSERT)
    public CommonResult addAudit(@RequestBody BuildAddAudit buildAddAudit) {
        return orgBuildAuditService.addAudit(buildAddAudit);
    }

    /**
     * 提交自然幢绑定审核
     *
     * @param orgRegionAudit 绑定的自然幢ID集合
     * @return 结果
     */
    @PostMapping("/submit")
    @LogRecord(description = "提交自然幢绑定审核", operationUnit = LogOperationUnit.ORG_BUILD, operationType = LogOperationType.UPDATE)
    public CommonResult submit(@RequestBody OrgRegionAudit orgRegionAudit) {
        return orgBuildAuditService.submit(orgRegionAudit);
    }

    /**
     * 绑定审核查询列表
     *
     * @param page           分页实体
     * @param orgRegionAudit 查询实体
     * @return 结果
     */
    @PostMapping("/getOrgRegionAuditList")
    @LogRecord(description = "绑定审核查询列表", operationUnit = LogOperationUnit.ORG_REGION, operationType = LogOperationType.SELECT)
    public PageInfo<Map<String, String>> getOrgRegionAuditList(Page page, OrgRegionAudit orgRegionAudit) {
        return orgBuildAuditService.getOrgRegionAuditList(page, orgRegionAudit);
    }
    /**
     * 绑定审核记录列表
     *
     * @param page           分页实体
     * @param baseBuildInfo 查询实体
     * @return 结果
     */
    @PostMapping("/getOrgBuildInfoByOrgRegionId")
    @LogRecord(description = "绑定审核记录列表", operationUnit = LogOperationUnit.ORG_BUILD, operationType = LogOperationType.SELECT)
    public PageInfo<Map<String, String>> getOrgBuildInfoByOrgRegionId(Page page, BaseBuildInfo baseBuildInfo) {
        return orgBuildAuditService.getOrgBuildInfoByOrgRegionId(page, baseBuildInfo);
    }
    /**
     * 绑定审核记录列表
     *
     * @param page           分页实体
     * @param orgBuildAudit 查询实体
     * @return 结果
     */
    @PostMapping("/selectByRegionAuditId")
    @LogRecord(description = "绑定审核记录详情", operationUnit = LogOperationUnit.ORG_BUILD, operationType = LogOperationType.SELECT)
    public PageInfo<OrgBuildAudit> selectByRegionAuditId(Page page, OrgBuildAudit orgBuildAudit) {
        return orgBuildAuditService.selectByRegionAuditId(page, orgBuildAudit);
    }
}
